<script type="text/javascript"><!--//--><![CDATA[//><!--

    var grid_import_reload = function() {
        $('#datagrid_import').treegrid('reload');
    };
    
	var f_new_import = function(){
		setLoading(false);
		$('#btn_import, #btn_new_import').hide();
		$('#label_file_import, #my_file, #btn_upload').fadeIn();
		$("#datagrid_import").treegrid("loadData", []);
	};
	
	var f_import_upload_file = function(){
		setLoading(true);
		$('#fm_upload_import').submit();
	};
	
	var f_import_file_to_db = function(as_filename){
		setLoading(true);
		$.ajax({
			type: 'POST', url: gs_path+'/'+controller+'/import_file_to_db', cache: false, data: { filename:as_filename, ajax: '0', culture: gs_localize, sessid: sessid },
			success: function(data) { setLoading(false); try{ eval(data); }catch(e){ alert(data); } },
			error: function(xhr, ajaxOptions, thrownError) { var ls_message = ''; if (xhr.status == 0) { ls_message = 'You are offline!!\n Please Check Your Network.'; } else if (xhr.status == 404) { ls_message = 'Requested URL not found.'; } else if (xhr.status == 500) { ls_message = 'Internal Server Error.'; } else if (thrownError == 'parsererror') { ls_message = 'Error.\nParsing JSON Request failed.' } else if (thrownError == 'timeout') { ls_message = 'Request Time out.'; } else { ls_message = 'Unknow Error.\n' + xhr.responseText; } alert(ls_message); setLoading(false); }, dataType: "html"
		});
	};
	
	var f_import_transfer = function(){
		setLoading(true);
		$.ajax({
			type: 'POST', url: gs_path+'/'+controller+'/import_transfer', cache: false, data: { ajax: '0', culture: gs_localize, sessid: sessid },
			success: function(data) { setLoading(false); try{ eval(data); }catch(e){ alert(data); } },
			error: function(xhr, ajaxOptions, thrownError) { var ls_message = ''; if (xhr.status == 0) { ls_message = 'You are offline!!\n Please Check Your Network.'; } else if (xhr.status == 404) { ls_message = 'Requested URL not found.'; } else if (xhr.status == 500) { ls_message = 'Internal Server Error.'; } else if (thrownError == 'parsererror') { ls_message = 'Error.\nParsing JSON Request failed.' } else if (thrownError == 'timeout') { ls_message = 'Request Time out.'; } else { ls_message = 'Unknow Error.\n' + xhr.responseText; } alert(ls_message); setLoading(false); }, dataType: "html"
		});
	};
	
    $(document).ready(function() {
		$('#btn_upload, #btn_import, #btn_new_import, #fm_search_import .easyui-linkbutton').linkbutton({  
			plain:true  
		});
		
		$('#my_file').change(function(){
			var ls_filename = $(this).val();
			
		});
		
		// Setup Datagrid
		$('#datagrid_import').treegrid({
            height: 358,
            nowrap: true,
            rownumbers: true,
            animate: true,
            //collapsible:true,
            idField: 'menu_id',
            treeField: 'menu_label',
            onBeforeLoad: function(row, param) {
                if (row) {
                    $(this).treegrid('options').url = gs_path + '/' + controller + '/getimportdatasubdata';
                } else {
                    $(this).treegrid('options').url = gs_path + '/' + controller + '/getimportdata';
                }
            }
        });
	});
//--><!]]></script>
<div id="tb_import" style="padding:5px;height:auto">
    <div>
        <form id="fm_upload_import" target="if_submit" action="<?php echo base_url().$this->data['controller_name'].'/process_upload_file' ?>" enctype="multipart/form-data" method="post">
        	<table class="tb_form" style="margin-bottom:0px; width:100%;">
            <tr>
            	<td width="100"><span id="label_file_import">Upload File (.json)</span></td>
                <td><input type="file" id="my_file" name="my_file" /></td>
                <td>
                	<div style="float:right;">
                        <a href="#" id="btn_upload" class="easyui-linkbutton" iconCls="icon-up" onclick="f_import_upload_file(); return false;">Upload</a>
                        <a href="#" id="btn_import" class="easyui-linkbutton" iconCls="icon-save" onclick="f_import_transfer(); return false;" style="display:none;">Import Data</a>
                        <a href="#" id="btn_new_import" class="easyui-linkbutton" iconCls="icon-menu" onclick="f_new_import(); return false;" style="display:none;">Upload Baru</a>
                    </div>
                </td>
            </tr>
            <tr>
            	<td colspan="3">
	            	<span style="color:#E60606; font-size:10px;">* Import file akan mereplace seluruh menu dengan APP_ID = <?php echo APP; ?></span>
                </td>
            </tr>
            </table>
        </form>
        <?php /*<form id="fm_search_import" onsubmit="grid_import_reload(); return false;" style="border-top:#CCC solid 1px; margin-top:6px;">
        	<table class="tb_form" style="margin-bottom:0px">
            <tr>
            	<td width="100">Keyword</td>
                <td><input type="text" id="keyword" name="keyword" class="textfield medium" />
                	<a href="#" class="easyui-linkbutton" iconCls="icon-search" onclick="grid_import_reload(); return false;">Search</a>
                    <a href="#" class="easyui-linkbutton" iconCls="icon-blank-file" onclick="$('#fm_search_import').resetForm(); return false;">Reset</a>
                </td>
            </tr>
            </table>
        </form>*/?>
    </div>
</div>
<table id="datagrid_import" toolbar="#tb_import">
<thead frozen="true">
    <tr>
        <th field="parent_menu_id" width="60" hidden="true">Parent Menu Id</th>
        <th field="menu_label" width="350">Label</th>
    </tr>
</thead>
<thead>
    <tr>
        <th field="url" width="250">URL</th>
        <th field="menu_id" width="90" align="center">Menu Id</th>
        <th field="order_num" width="70" align="center">No.Urut</th>
        <th field="status" width="70" align="center" formatter="f_status">Status</th>
    </tr>
</thead>
</table>
<?php if(isset($title)){ ?><script type="text/javascript">$('#datagrid_import').parent().parent().parent().parent().parent().parent().parent().find('.panel-title').html('<?php echo addslashes($title); ?>');</script><?php } ?>